package com.touchdrive;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.touchdrive.TouchPad;
//import android.view.MenuItem;

public class MainActivity extends Activity {
    @Override
    protected void onStart(){
    	Log.d(WINDOW_SERVICE, "onStart Called");
        final TextView textView = (TextView)findViewById(R.id.textView);
        final View touchView = findViewById(R.id.touchView);
        final View vertical = findViewById(R.id.vertical);
        final View horizontal = findViewById(R.id.horizontal);
    	final TouchPad touchpad = new TouchPad();
    	touchpad.padSizeX=touchView.getWidth();
        touchpad.padSizeY=touchView.getHeight();
        touchpad.deadZone();
        touchView.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
        	switch(event.getAction()){
        	case MotionEvent.ACTION_DOWN | MotionEvent.ACTION_MOVE:{
		    	touchpad.position((int)event.getX(), (int)event.getY(), true);
		        textView.setText(String.valueOf(touchpad.XPos) + ", " + String.valueOf(touchpad.YPos));
		        vertical.layout(touchpad.lowerX, 0, touchpad.upperX, touchpad.padSizeY);
		        horizontal.layout(0, touchpad.lowerY, touchpad.padSizeX, touchpad.upperY);
		        break;
        	}
        	case MotionEvent.ACTION_UP:{
        		touchpad.position(0, 0, false);
        		textView.setText(String.valueOf(touchpad.XPos) + ", " + String.valueOf(touchpad.YPos));
        		break;
        	}/* */
        	}
            
        return true;	
        }} );
               
        
        super.onStart();
    }
   
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(WINDOW_SERVICE, "Main Launch");
        }
    
 /**/

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
//    	getMenuInflater().inflate(R.menu.activity_main, menu);
    	startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
        return false;
    }
	
/*	public boolean onOptionsItemSelected(MenuItem item) {
        Log.d(WINDOW_SERVICE, "Settings Launch");
		super.onOptionsItemSelected(item);
        switch (item.getItemId()) {
            case R.id.menu_settings:
            	startActivity(new Intent(this, SettingsActivity.class));
            	return true;
        }
        return true;
    }
    /**/
}
